package com.Ajava1704.for线程池;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 作者: LCG
 * 日期: 2020/2/11 08:58
 * 描述:
 */
public class ForRejectHandler implements RejectedExecutionHandler {

    private LinkedBlockingQueue<Runnable> linkedBlockingQueue;

    public ForRejectHandler(LinkedBlockingQueue<Runnable> linkedBlockingQueue) {
        this.linkedBlockingQueue = linkedBlockingQueue;
    }

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {

        //executor.execute(r);
        try {
            linkedBlockingQueue.put(r);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
